var htmlCodes = [
    '<div  >',
    '                <!--操作-->',
    '                <el-card shadow="always">',
    '                    <div slot="header" class="clearfix">',
    '                        <span>操作</span>',
    '                    </div>',
    '                    <div style=" text-align:center">',
    '                        <el-button size="small" type="primary" icon="el-icon-check" @click="saveOptionSpecial">保存</el-button>',
    '                        <el-button size="small" icon="el-icon-back" @click="goBackOptionSpecialList">返回</el-button>',
    '                    </div>',
    '                </el-card>',
    '                <!--顶部筛选-->',
    '                <el-card shadow="always">',
    '                    <div slot="header" class="clearfix">',
    '                        <span>主要信息</span>',
    '                    </div>',
    '                    <el-form :inline="true" :model="special" :rules="specialRules"',
    '                             size="small" ref="optionSpecialForm" label-width="80px" class="demo-form-inline">',
    '                        <el-form-item label="分类" prop="categoryId">',
    '                            <el-select  v-if="isAdd == 0"',
    '                                        v-model="special.categoryId" placeholder="请选择分类" @change="optionCategoryChange">',
    '                                <el-option',
    '                                        v-for="item in categoryList"',
    '                                        :key="item.categoryId"',
    '                                        :label="item.categoryName"',
    '                                        :value="item.categoryId">',
    '                                </el-option>',
    '                            </el-select>',
    '                            <el-input  v-if="isAdd == 1" v-model="special.categoryName" disabled></el-input>',
    '                        </el-form-item>',
    '                        <el-form-item label="部件" v-if="partsList.length >0 || special.partsId != null " prop="partsId" >',
    '                            <el-select v-if="isAdd == 0"',
    '                                    v-model="special.partsId" placeholder="请选择部件" @change="optionPartsChange">',
    '                                <el-option',
    '                                        v-for="item in partsList"',
    '                                        :key="item.id"',
    '                                        :label="item.partsName"',
    '                                        :value="item.id">',
    '                                </el-option>',
    '                            </el-select>',
    '                            <el-input  v-if="isAdd == 1 && special.partsId!= null" v-model="special.partsName" disabled></el-input>',
    '                        </el-form-item>',
    '                        <el-form-item label="属性" prop="attributeId" >',
    '                            <el-select  v-if="isAdd == 0"',
    '                                        v-model="special.attributeId" placeholder="请选择属性" @change="attributeChange">',
    '                                <el-option',
    '                                        v-for="item in attributeList"',
    '                                        :key="item.attributeId"',
    '                                        :label="item.attributeName"',
    '                                        :value="item.attributeId">',
    '                                </el-option>',
    '                            </el-select>',
    '                            <el-input  v-if="isAdd == 1" v-model="special.attributeName" disabled></el-input>',
    '                        </el-form-item>',
    '                        <el-form-item label="选项" v-show="isMaterial==false"  prop="optionId" >',
    '                            <el-select  v-if="isAdd == 0"',
    '                                        v-model="special.optionId" placeholder="请选择选项" @change="optionChange">',
    '                                <el-option',
    '                                        v-for="item in optionList"',
    '                                        :key="item.optionId"',
    '                                        :label="item.optionName"',
    '                                        :value="item.optionId">',
    '                                </el-option>',
    '                            </el-select>',
    '                            <el-input  v-if="isAdd == 1" v-model="special.optionName" disabled></el-input>',
    '                        </el-form-item>',
    '                        <el-form-item label="选项" v-show="isMaterial==true"  prop="optionKey" >',
    '                            <el-select  v-if="isAdd == 0"',
    '                                        v-model="special.optionKey" placeholder="请选择材料选项" @change="optionKeyChange">',
    '                                <el-option',
    '                                        v-for="item in optionKeyList"',
    '                                        :key="item.optionKey"',
    '                                        :label="item.optionName"',
    '                                        :value="item.optionKey">',
    '                                </el-option>',
    '                            </el-select>',
    '                            <el-input  v-if="isAdd == 1" v-model="special.optionName" disabled></el-input>',
    '                        </el-form-item>',
    '                        <el-form-item label="克重" v-show="isMaterial==true"  prop="optionId" >',
    '                            <el-select  v-if="isAdd == 0"',
    '                                        v-model="special.optionId" placeholder="请选择克重" @change="optionMaterialChange">',
    '                                <el-option',
    '                                        v-for="item in optionMaterialList"',
    '                                        :key="item.optionId"',
    '                                        :label="item.optionName2"',
    '                                        :value="item.optionId">',
    '                                </el-option>',
    '                            </el-select>',
    '                            <el-input  v-if="isAdd == 1" v-model="special.optionName2" disabled></el-input>',
    '                        </el-form-item>',
    '                        <el-form-item label="工艺必须" prop="optionMustChoice">',
    '                            <el-select v-model="special.optionMustChoice">',
    '                                <el-option label="是" :value="1"></el-option>',
    '                                <el-option label="否" :value="0"></el-option>',
    '                            </el-select>',
    '                        </el-form-item>',
    '                </el-form>',
    '                </el-card>',
    '                <!--自定义属性部分-->',
    '                <el-card shadow="always" >',
    '                    <div slot="header" class="clearfix">',
    '                        <span>自定义属性</span>',
    '                    </div>',
    '                    <el-form :model="special" ref="optionSpecialDefineForm" size="small" label-width="100px" class="demo-dynamic">',
    '                        <el-form-item label="是否自定义" required>',
    '                            <el-select v-model="special.optionIgnoreDefinition" >',
    '                                <el-option label="是" :value="1"></el-option>',
    '                                <el-option label="否" :value="0"></el-option>',
    '                            </el-select>',
    '                            <el-button type="primary" size="mini" icon="el-icon-plus"',
    '                                       @click.prevent="addOptionDefLength"',
    '                                       v-show="special.optionIgnoreDefinition==1">新增',
    '                            </el-button>',
    '                        </el-form-item>',
    '                        <el-form-item',
    '                                style="width: 500px"',
    '                                v-if="special.optionDefinitionLength.length >0 && special.optionIgnoreDefinition==1"',
    '                                v-for="(optionDef, index) in special.optionDefinitionLength"',
    '                                :label="\'自定义参数\' + index"',
    '                                :prop="\'optionDefinitionLength\'+index"',
    '                                :rules="[',
    '                                      {data: optionDef, validator:validateOptionDefLength,trigger: \'change\'}',
    '                                    ]"',
    '                                >',
    '                            <el-row :gutter="20">',
    '                                <el-col :span="9">',
    '                                    <el-input v-model.number="optionDef[0]" placeholder="最小值"></el-input>',
    '                                </el-col>',
    '                                <el-col class="line" :span="1">-</el-col>',
    '                                <el-col :span="9">',
    '                                    <el-input v-model.number="optionDef[1]" placeholder="最大值"></el-input>',
    '                                </el-col>',
    '                                <el-col class="line" :span="3">',
    '                                    <el-button size="mini" type="danger" icon="el-icon-delete" circle  @click.prevent="removeOptionDefLength(index)"></el-button>',
    '                                </el-col>',
    '                            </el-row>',
    '                        </el-form-item>',
    '                </el-form>',
    '                </el-card>',
    '                <!--属性-选项互斥部分-->',
    '                <el-card shadow="always" >',
    '                    <div slot="header" class="clearfix">',
    '                        <span>属性-选项互斥</span>',
    '                    </div>',
    '                    <el-checkbox-group  v-model="attributeOutIds" >',
    '                        <el-checkbox v-for="item  in attributeList"',
    '                                     :label="item.attributeId"',
    '                                     :key="item.attributeId"',
    '                                     size="medium"',
    '                                     border >',
    '                            {{item.attributeName}}',
    '                        </el-checkbox>',
    '                    </el-checkbox-group>',
    '                </el-card>',
    '                <!--选项-选项互斥部分-->',
    '                <el-card shadow="always" >',
    '                    <div slot="header" class="clearfix">',
    '                        <span>选项-选项互斥</span>',
    '                    </div>',
    '                   <el-table :data="optionOutIdsTableData" style="width: 100%" size="mini" border>',
    '                       <el-table-column prop="attributeName" label="属性/材料" width="180">  </el-table-column>',
    '                       <el-table-column  label="选项/克重" > ' +
    '                            <template slot-scope="scope">' +
    '                             <el-checkbox-group  v-model="outIds[scope.row.attributeId]" >',
    '                                <el-checkbox v-for="item  in scope.row.optionList"',
    '                                     :label="item.optionId"',
    '                                     :key="item.optionId"',
    '                                     size="medium"',
    '                                      >',
    '                                       {{item.optionName}}',
    '                                  </el-checkbox>',
    '                              </el-checkbox-group>',
    '                            </template>' +
    '                       </el-table-column>',
    '                   </el-table>',
    '                </el-card>',
    '            </div>'
].join("");

Vue.component('zy-option-special', {
    template: htmlCodes,
    props: {
        isAdd: null, // 0新增 1 编辑
        id: null,//编辑时所需id
    },
    data() {
        return {
            special: {},//属性特规参数
            categoryList: [], //商品分类列表
            partsList: [],// 部件列表
            attributeList: [],// 属性列表
            optionList: [],// 选项列表
            optionAllList: [],//当前 分类/部件下 所有选项
            optionKeyList: [],// 克重列表
            optionMaterialList: [],//材料选项列表
            outIds: {},// 属性-属性互斥
            attributeOutIds: [],// 属性-选项互斥
            isMaterial: false,// 是否为材料
            optionOutIdsTableData: [],//选项 -选项 互斥列表
            specialRules: {
                categoryId: [{required: true, message: '请选择分类', trigger: 'change'}],
                partsId: [{required: true, message: '请选择部件', trigger: 'change'}],
                attributeId: [{required: true, message: '请选择属性', trigger: 'change'}],
                optionId: [{required: true, message: '请选择选项', trigger: 'change'}],
                optionKey: [{required: true, message: '请选择材料选项', trigger: 'change'}],
            },
        }
    },

    methods: {
        // 添加属性特规
        addOptionSpecial: function () {
            //获取增加属性所需初始数据
            var self = this;
            $.get(baseURL + "quoteProductAttributeOptionRelation/quoteproductattributeoptionrelation/addOptionSpecialInfo", function (r) {
                if (r.code == 0) {
                    self.categoryList = r.categoryList;
                    self.special = r.quoteOptionSpecial;
                    // 自定义属性特殊处理
                    self.$set(self.special, 'optionDefinitionLength', []);
                    if (self.special.optionDefinitionLength == 1) {
                        self.addOptionDefLength();
                    }
                } else {
                    alert(r.msg());
                }
            });


        },

        //编辑属性特规
        handleEditOptionSpecial: function (id) {
            // 获取详情
            var self = this;
            $.get(baseURL + "quoteProductAttributeOptionRelation/quoteproductattributeoptionrelation/optionSpecialInfo/" + id, function (r) {
                if (r.code == 0) {
                    self.pecialRules = {};//置空 主要信息表单规则
                    self.special = r.quoteOptionSpecial;
                    self.attributeList = r.attributeList;
                    self.optionAllList = r.optionAllList;
                    // 自定义属性特殊处理
                    if (self.special.optionDefinitionLength) {
                        vm.$set(self.special, 'optionDefinitionLength',
                            JSON.parse(self.special.optionDefinitionLength));
                    } else {
                        self.$set(self.special, 'optionDefinitionLength', []);
                    }
                    // 属性 互斥处理
                    self.handleAttributeOutIdsShow();
                    self.handleOutIdsShow();

                } else {
                    alert(r.msg);
                }
            });

        },

        // 处理编辑页面 属性-选项互斥展示
        handleAttributeOutIdsShow: function () {
            if (this.special.optionAttributeOutIds){
                if (Object.keys(JSON.parse(this.special.optionAttributeOutIds)).length>0 ){
                    this.attributeOutIds = JSON.parse(this.special.optionAttributeOutIds)[this.special.optionId];
                }
            }
        },

        // 处理编辑页面 选项-选项互斥展示
        handleOutIdsShow: function () {
            //处理 optionOutIdsTableData 数据
            this.resetOutIds();
            //处理选中项
            var allSelectedOptionArr = [];
            if (this.special.optionOptionOutIds) {
                var optionOptionOutIdArr = JSON.parse(this.special.optionOptionOutIds);
                for (var i  in  optionOptionOutIdArr) {
                    var temp = optionOptionOutIdArr[i];
                    if (temp[0] === this.special.optionId) {
                        allSelectedOptionArr.push(temp[1])
                    }
                    if (temp[1] === this.special.optionId) {
                        allSelectedOptionArr.push(temp[0])
                    }
                }
            }
            // 循环 optionOutIdsTableData 赋值 outIds
            for (var i in this.optionOutIdsTableData){
                var attributeId = this.optionOutIdsTableData[i].attributeId;
                var optionList = this.optionOutIdsTableData[i].optionList;
                //取出 选中的optionId
                var selectedOptionList =[];
                for (var k  in optionList){
                    if(allSelectedOptionArr.indexOf(optionList[k].optionId) > -1){
                        selectedOptionList.push(optionList[k].optionId);
                    }
                }
                Vue.set(this.outIds,attributeId,selectedOptionList);
            }

        },

        //属性特规 分类变化
        optionCategoryChange: function (value) {
            // 查询该分类是否有部件
            var self = this;
            $.get(baseURL + "quoteProduct/quoteproductbaseinfo/getParts?categoryId=" + value, function (r) {
                if (r.code == 0) {
                    if (r.partsList.length > 0) {
                        self.partsList = r.partsList;
                        self.special.partsId = null;
                        //置空属性列表
                        self.attributeList = [];
                        self.special.attributeId = null;
                        self.optionList = [];
                        self.optionAllList = [];
                        self.optionMaterialList = [];
                        self.special.optionId = null;
                        self.optionKeyList = [];
                        self.special.optionKey = null;
                        //互斥
                        self.optionOutIdsTableData = [];
                        self.outIds = {};
                        self.attributeOutIds = [];

                    } else {
                        // 直接查询该分类下的属性
                        $.get(baseURL + "quoteProductAttributeOptionRelation/quoteproductattributeoptionrelation/getAttributes?" +
                            "categoryId=" + self.special.categoryId, function (r) {
                            if (r.code == 0) {
                                self.attributeList = r.attributeList;
                                self.special.attributeId = null;
                                //置空部件列表
                                self.partsList = [];
                                self.special.partsId = null;
                                self.optionList = [];
                                self.optionAllList = [];
                                self.optionMaterialList = [];
                                self.special.optionId = null;
                                self.optionKeyList = [];
                                self.special.optionKey = null;

                                //互斥
                                self.optionOutIdsTableData = [];
                                self.outIds = {};
                                self.attributeOutIds = [];

                            } else {
                                alert(r.msg);
                            }
                        });
                    }
                } else {
                    alert(r.msg);
                }
            });
        },

        //属性特规 部件变化
        optionPartsChange: function (value) {
            var self = this;
            // 查询该部件下属性
            $.get(baseURL + "quoteProductAttributeOptionRelation/quoteproductattributeoptionrelation/getAttributes?" +
                "partsId=" + value + "&categoryId=" + self.special.categoryId, function (r) {
                if (r.code == 0) {
                    self.attributeList = r.attributeList;
                    self.special.attributeId = null;
                    // 清空选项
                    self.optionList = [];
                    self.optionAllList = [];
                    self.optionMaterialList = [];
                    self.special.optionId = null;
                    self.optionKeyList = [];
                    self.special.optionKey = null;

                    //互斥
                    self.optionOutIdsTableData = [];
                    self.outIds = {};
                    self.attributeOutIds = [];
                } else {
                    alert(r.msg);
                }
            });
        },

        //属性特规 属性变化
        attributeChange: function (value) {
            // 查找选项
            var self = this;
            var urlParams = "attributeId=" + value + "&categoryId=" + self.special.categoryId;
            if (self.special.partsId) {
                urlParams += "&partsId=" + self.special.partsId;
            }
            $.get(baseURL + "quoteProductAttributeOptionRelation/quoteproductattributeoptionrelation/getOptions?" + urlParams, function (r) {
                if (r.code == 0) {
                    self.optionList = r.optionList;
                    self.optionAllList = r.optionAllList;
                    // 置空数据
                    self.special.optionId = null;
                    self.optionMaterialList = [];
                    self.optionKeyList = [];
                    self.special.optionKey = null;

                    //互斥
                    self.optionOutIdsTableData = [];
                    self.outIds = {};
                    self.attributeOutIds = [];

                    var currentAttribute = self.attributeList.find(function (data) {
                        return data.attributeId === value;
                    });
                    if (currentAttribute.attributeType === 'material') {
                        // 判断是否是材料
                        self.isMaterial = true;
                        self.optionKeyList = handleMaterialOption($.extend(true, [], r.optionList));
                    } else {
                        self.isMaterial = false;
                    }
                    //重置 选项与选项互斥Table
                    self.resetOutIds();
                } else {
                    alert(r.msg);
                }
            });


        },

        //重置 选项与选项互斥 Table
        resetOutIds: function () {
            //属性发生变化 重新组装 选项与选项互斥table
            this.optionOutIdsTableData = [];
            //1.属性列表 除去当前属性
            if (this.attributeList.length > 0) {
                // 克隆一份 最新备份数据
                this.attributeListCopy = $.extend(true, [], this.attributeList);
                // 移除 attributeListCopy 当前值
                var self = this;
                var index = this.attributeListCopy.findIndex(function (data) {
                    return data.attributeId === self.special.attributeId;
                });
                if (index !== -1) {
                    this.attributeListCopy.splice(index, 1)
                }
                //2. 遍历属性 找到对应的选项
                for (var index in this.attributeListCopy) {
                    var attributeTemp = this.attributeListCopy[index];

                    //判断是否材料
                    if (attributeTemp.attributeType === 'material') {
                        // 材料需要将 optionKey做为属性,optionName2 做为选项
                        //找出材料的所有选项
                        var filterArray = $.grep(this.optionAllList, function (data, index) {
                            return data.attributeId === attributeTemp.attributeId;
                        });
                        //循环optionKeyList
                        var optionKeyListTemp = handleMaterialOption(filterArray);
                        for (var i in  optionKeyListTemp) {
                            var optionOutIdsTable = {};
                            optionOutIdsTable.attributeName = optionKeyListTemp[i].optionName;
                            optionOutIdsTable.attributeId = optionKeyListTemp[i].optionKey;
                            // 查找相应的 option
                            var filterArray = $.grep(this.optionAllList, function (data, index) {
                                return data.optionKey === optionKeyListTemp[i].optionKey;
                            });
                            //将optionName2 转换为optionName
                            for (var j in filterArray) {
                                filterArray[j].optionName = filterArray[j].optionName2;
                            }
                            optionOutIdsTable.optionList = filterArray;
                            this.optionOutIdsTableData.push(optionOutIdsTable);
                        }
                    } else {
                        // 非材料直接 取attributeList 并查找对应的option即可
                        var optionOutIdsTable = {};
                        optionOutIdsTable.attributeName = attributeTemp.attributeName;
                        optionOutIdsTable.attributeId = attributeTemp.attributeId;

                        var filterArray = $.grep(this.optionAllList, function (data, index) {
                            return data.attributeId === attributeTemp.attributeId;
                        });
                        optionOutIdsTable.optionList = filterArray;
                        this.optionOutIdsTableData.push(optionOutIdsTable);
                    }
                }
            }

            if (this.optionOutIdsTableData.length > 0) {
                //动态生成outIds
                for (var i in this.optionOutIdsTableData) {
                    Vue.set(this.outIds, this.optionOutIdsTableData[i].attributeId, []);
                }
            }
        },

        // 一般选项变化
        optionChange: function (value) {

        },

        // 材料 key变化
        optionKeyChange: function (value) {
            this.optionMaterialList = [];
            this.special.optionId = null;
            // 根据optionKey找出对应的 选项ID
            var filterArray = $.grep(this.optionList, function (data, index) {
                return data.optionKey === value;
            });
            this.optionMaterialList = filterArray;

        },

        // 材料选项变化
        optionMaterialChange: function (value) {

        },

        //新增自定义参数
        addOptionDefLength: function () {
            this.special.optionDefinitionLength.push([]);
        },

        //移除自定义参数
        removeOptionDefLength: function (index) {
            this.special.optionDefinitionLength.splice(index, 1)
        },

        // 自定义校验
        validateOptionDefLength: function (rule, value, callback) {
            if (rule.data.length == 0) {
                callback(new Error('自定义参数不能为空!'));
            } else if (rule.data.length == 1) {
                callback(new Error('最小值与最大值不能为空!'));
            } else if (isNaN(rule.data[0])) {
                callback(new Error('最小值必须为数值!'));
            } else if (isNaN(rule.data[1])) {
                callback(new Error('最大值必须为数值!'));
            } else {
                callback();
            }
        },

        //保存 属性特规
        saveOptionSpecial: function () {
            /* 规则校验
               1.分类ID 不能为空(表单直接校验)
               2.属性ID 不能为空(表单直接校验)
               3.若选择了自定义 则必须设置自定义参数 且2个值仅为数字不能为空(手动校验)
            */
            var flag = this.validateForm();
            flag = this.validateDefinition();
            if (!flag) {
                return;
            }
            //将属性互斥属性转换为 map
            var mapAttributeOutIds = this.handleAttributeOutIdsForm();

            //将属性互斥转为 list
            var outIds = this.handleOutIdsForm();


            //克隆对象 提交

            var postData = $.extend(true, {}, this.special);
            if (mapAttributeOutIds) {
                postData.optionAttributeOutIds = JSON.stringify(mapAttributeOutIds);
            } else {
                postData.optionAttributeOutIds = JSON.stringify({});
            }
            if (outIds.length > 0) {
                postData.optionOptionOutIds = JSON.stringify(outIds);
            } else {
                postData.optionOptionOutIds = JSON.stringify([]);;
            }
            if (postData.optionDefinitionLength.length > 0) {
                postData.optionDefinitionLength = JSON.stringify(postData.optionDefinitionLength);
            } else {
                postData.optionDefinitionLength = JSON.stringify([]);
            }
            // 异步提交即可;
            var self = this;
            this.$confirm('确定要保存吗, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                const loading = self.$loading({
                    lock: true,
                    text: '保存中,请勿刷新页面',
                    spinner: 'el-icon-loading'
                });
                $.ajax({
                    type: "POST",
                    url: baseURL + "quoteProductAttributeOptionRelation/quoteproductattributeoptionrelation/saveOrUpdateOptionSpecial",
                    contentType: "application/json",
                    data: JSON.stringify(postData),
                    success: function (r) {
                        loading.close();
                        if (r.code == 0) {
                            alert(r.msg, function (index) {
                                self.goBackOptionSpecialList();
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            }).catch(() => {
                //loading.close();
            });

        },

        // 表单校验
        validateForm: function () {
            var flag = true;
            this.$refs['optionSpecialForm'].validate((valid) => {
                if (!valid) {
                    flag = false;
                    return false;
                }
            });
            this.$refs['optionSpecialDefineForm'].validate((valid) => {
                if (!valid) {
                    flag = false;
                    return false;
                }
            });

            return flag;
        },

        //校验自定义长度
        validateDefinition: function () {
            var flag = true;
            if (this.special.optionIgnoreDefinition == 1) {
                if (this.special.optionDefinitionLength.length >= 0) {
                    // 循环校验 非空且为Number;
                    for (var index in this.special.optionDefinitionLength.length) {
                        var temp = this.special.optionDefinitionLength[index];
                        if (temp.length == 0) { //2个参数为空 直接移除
                            this.special.optionDefinitionLength.splice(index, 1);
                        }
                    }
                }
                if (this.special.optionDefinitionLength.length == 0) {
                    this.$message.error('选择自定时 必须填写自定义参数!');
                    flag = false;
                    return;
                }
            }
            if (this.special.optionIgnoreDefinition == 0) {
                this.special.optionDefinitionLength.splice(0);
            }
            return flag;
        },

        //处理 属性选项互斥 提交表单
        handleAttributeOutIdsForm: function () {
            //将互斥属性转换为 数组 存入special
            var mapAttributeOutIds = {};
            if (this.attributeOutIds && this.attributeOutIds.length > 0) {
                // 当前选项ID
                var optionId = this.special.optionId;
                //组装成map{"选项ID":属性列表}
                mapAttributeOutIds[optionId] = this.attributeOutIds;
            }
            return mapAttributeOutIds;
        },
        // 处理 选项选项互斥 提交表单
        handleOutIdsForm: function () {
            var outIds = [];
            if (this.outIds) {
                //取出当前选项
                var optionId = this.special.optionId;
                for (var i in this.outIds) {
                    if (this.outIds[i].length > 0) {
                        //每行属性 已选中的选项
                        for (var j in this.outIds[i]) {
                            var temp = this.outIds[i][j];
                            var tempArr = [];
                            if (temp < optionId) { //将小Id的选项 放第一次列
                                tempArr[0] = temp;
                                tempArr[1] = optionId;
                            } else {
                                tempArr[0] = optionId;
                                tempArr[1] = temp;
                            }
                            outIds.push(tempArr);
                        }
                    }
                }
            }
            return outIds;
        },

        goBackOptionSpecialList: function () {
            //情况编辑部分数据
            this.special = {};
            this.categoryList = [],//商品分类列表
                this.partsList = [],//部件列表
                this.optionList = [];
            this.optionAllList = [];
            this.optionMaterialList = [];
            this.optionKeyList = [];
            //互斥
            this.optionOutIdsTableData = [];
            this.outIds = {};
            this.attributeOutIds = [];

            this.$refs['optionSpecialDefineForm'].resetFields();
            this.$refs['optionSpecialForm'].resetFields();

            //抛出返回事件
            this.$emit('go-back-option', null);

        },

    },
});

//解析材料参数
function handleMaterialOption(rps) {
    //循环解析出 选项
    var optionList = [];
    $.each(rps, function (index, element) {
        var option = {'optionKey': element.optionKey, 'optionName': element.optionName};
        var flag = true;
        for (var i = 0; i < optionList.length; i++) {
            if (JSON.stringify(option) == JSON.stringify(optionList[i])) {
                flag = false;
                return true;
            }
        }
        if (flag) { //去重 插入选项
            optionList.push(option);
        }
    })
    return optionList;
}